<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Administrator Login Page</title>
        <script type="text/javascript" src="<?php echo getJsUrl(); ?>mootools-core.js"></script>
        <script type="text/javascript" src="<?php echo getJsUrl(); ?>mootools-more.js"></script>
        <script type="text/javascript">
        window.addEvent("domready", function(){
            $('username').focus();
            
            $('login_form').addEvent("submit", function(e){
                e.stop();
                if(!$('username').get('value').length) {
                    $('username').focus();
                    $('username').highlight();
                } else if(!$('password').get('value').length) {
                    $('password').focus();
                    $('password').highlight();
                } else {
                    $('login_form').set('send', {
                       onSuccess: function(r){
                           var response = JSON.decode(r);
                           if(response.result) {
                               window.location = "<?php echo getHttpUrl() . 'admin'; ?>";
                           } else {
                               alert(response.message);
                           }
                       },
                       onFailure: function(e){
                           alert(e.status);
                       }
                    });

                    /*$('login_form').set('send', {
                        onSuccess: function(E) {
                            alert(E);
                        }
                    });*/
                    $('login_form').send();
                }
            })
        });
        </script>
    </head>
    <body>
        <?php if(isset($error)): ?>
        <p style="color: red;"><?php echo $error; ?></p>
        <?php endif; ?>
        <form id="login_form" method="post" action="<?php echo getAppUrl('admin','check_login'); ?>">
            <p>
                <span>username : </span>
                <input id="username" name="username"/>
            </p>
            <p>
                <span>password : </span>
                <input id="password" name="password" type="password"/>
            </p>
            <p>
                <input id="submit" name="submit" type="submit" value="Submit"/>
            </p>
        </form>
    </body>
</html>
